#ifndef _OI_PLSCANNERCORE_DATABASE_HPP_
#define _OI_PLSCANNERCORE_DATABASE_HPP_

#include "PLScannerCore/OiPLScannerCore.hpp"
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlDriver>
#include <QtSql/QSqlError>
#include <QtSql/QSqlRecord>
namespace Oi
{
    namespace PLScannerCore
    {
        struct OI_PLSCANNER_CORE_API DataRow
        {
            int result;
            QDateTime datetime;
            QString formula;
            QString user;
            int team;
            double width;
            double widthEl;
            double thickness1;
            double thickness2;
            double thickness3;
            double thickness4;
            double thickness5;
            QList<double> lstThickness;
            QList<double> lstThicknessStd;
            QList<double> lstThicknessErr;
            QList<double> lstThicknessDif;
            double widthStd;
            double widthElStd;
            double widthErr;
            double thickness1Std;
            double thickness1Err;
            double thickness2Std;
            double thickness2Err;
            double thickness3Std;
            double thickness3Err;
            double thickness4Std;
            double thickness4Err;
            double thickness1Dif;
            double thickness2Dif;
            double thickness3Dif;
            double thickness4Dif;
            double edgeThicknessDif;
            OiProfile profile;
        };

        struct OI_PLSCANNER_CORE_API FixedValueRow
        {
            int result;
            QDateTime datetime;
            QString formula;
            QString user;
            int team;
            double value;
            double stdValue;
            double errValue;
           // double width;
        };

        class OI_PLSCANNER_CORE_API Database : public QObject
        {
            Q_OBJECT

        public:
            Database();
            ~Database();

        public:
            QString tableName() const;
            QSqlDatabase sqlDatabase() const;
            QString fixedTableName() const;

            bool open();

        public:
            bool queryAll(QList<DataRow>& datas, const QDateTime from, const QDateTime end);
            bool query(const QStringList keys, QMap<QString, QList<QPointF>>&, const QDateTime from, const QDateTime end);

            bool queryFixedValues(const QStringList keys, QMap<QString, QList<QPointF>>&, const QDateTime from, const QDateTime end);
//            bool query(QMap<QString, QList<QPointF>>& datas, const QString toolName, const QString formular, const QDateTime from, const QDateTime end);
// 
//             bool query(QMap<qreal, int>& ids, QMap<qreal, int>& results, const QString formular, const QDateTime from, const QDateTime end);
// 
//             bool query(QMap<qreal, int>& ids, QMap<qreal, int>& results, const QDateTime from, const QDateTime end);
// 
//             bool query(DataRow& row, int id);

            QStringList group(const QString key, const QString db);

        public:
            bool insert(const DataRow&);
            bool insert(const FixedValueRow&);
           // bool insertSpliceData(const int id, const QByteArray data);


        public:
            static Database* instance();

        private:
            OI_DISABLE_COPY(Database);
            OI_DECLARE_IMPL(Database);
        };
    }
}

#endif
